FROM golang:1.19-alpine AS builder
ARG main_path
ADD . /task
WORKDIR /task
ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct
RUN cd /task && go mod download && go mod tidy
RUN cd /task/cmd/$main_path && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /task/main

FROM alpine:3.16
COPY --from=builder /task/main /main
COPY --from=builder /task/templates /templates
COPY --from=builder /task/config/task.yml /task.yml
RUN chmod +x /main
ENV TZ=Asia/Shanghai
ENTRYPOINT ["/main"]